package com.charm.information

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.alibaba.android.arouter.facade.annotation.Route
import com.charm.information.adapter.ChannelAdapter
import com.charm.information.entity.ChannelEntity
import com.flyco.tablayout.SlidingTabLayout
import me.yokeyword.fragmentation.SupportFragment

/**
 * Created by tools on 2018/1/2.
 */
@Route(path = "/information/main/fragment")
class InformationFragment : SupportFragment() {
    private lateinit var tabLayout: SlidingTabLayout
    private var viewPager: ViewPager? = null
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        var rootView: View = inflater!!.inflate(R.layout.fragment_information, container, false)
        initView(rootView)
        return rootView
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
    }

    private fun initView(rootView: View) {
        tabLayout = rootView.findViewById(R.id.tab_layout)
        viewPager = rootView.findViewById(R.id.pager)
    }

    private fun initData() {
        var chanelList: ArrayList<ChannelEntity> = ArrayList()
        chanelList.add(ChannelEntity("yule", "娱乐"))
        chanelList.add(ChannelEntity("jijin", "基金"))
        chanelList.add(ChannelEntity("baoxian", "保险"))
        chanelList.add(ChannelEntity("dejia", "德甲"))
        chanelList.add(ChannelEntity("qiche", "体育"))
        chanelList.add(ChannelEntity("huangjin", "黄金"))
        chanelList.add(ChannelEntity("caijing", "财经"))
        chanelList.add(ChannelEntity("xingzuo", "星座"))
        chanelList.add(ChannelEntity("qipai", "棋牌"))
        var channelAdapter = ChannelAdapter(childFragmentManager, chanelList)
        viewPager!!.adapter = channelAdapter
        tabLayout!!.setViewPager(viewPager)
    }


}